<?php
class pemberian_beasiswa extends MY_Controller{
    var $data;
    function pemberian_beasiswa(){
        parent::MY_Controller();
        $this->data['title'] = "Transaksi Pemberian Beasiswa";
        $this->load->model('m_pemberian_beasiswa'); 
        $this->load->model('m_adik_asuh'); 
        $this->load->model('m_keuangan_adik_asuh'); 
    }
    function index(){
        $this->data['content'] = "pemberian_beasiswa/v_pemberian_beasiswa";
        $this->data['subLink'] = "pemberian_beasiswa/pemberian_beasiswa_proses";
        $this->data['formTitle'] = "Form Pemberian Beasiswa";
        
        $this->render($this->data);
    }
    function pemberian_beasiswa_proses(){
        $id_adik_asuh = $this->input->post('id_adik_asuh');
        $jumlah = currencyToNumber($this->input->post('jumlah'));
        $keterangan = $this->input->post('keterangan');
        $id_sekolah = $this->input->post('id_sekolah');
        $id_kelas = $this->input->post('id_kelas');
        $tanggal = date2mysql($this->input->post('tanggal'));
        $id_tahun_ajaran = $this->input->post('id_tahun_ajaran');
        $debet = $this->m_adik_asuh->getTotalDebet($id_adik_asuh);
        $kredit = $this->m_adik_asuh->getTotalKredit($id_adik_asuh);
        foreach ($debet as $totalDebet);
        foreach ($kredit as $totalKredit);
        $data = array('id_adik_asuh' => $id_adik_asuh,
            'jumlah' => $jumlah,
            'tanggal' => $tanggal,
            'keterangan' => $keterangan,
            'id_sekolah' => $id_sekolah,
            'id_kelas' => $id_kelas,
            'id_tahun_ajaran' => $id_tahun_ajaran,
            'total_debet' => $totalDebet['total_debet'],
            'total_kredit' => $totalKredit['total_kredit']
            );
        $insert = $this->m_pemberian_beasiswa->addBeasiswa($data);
        if($insert['status'] == TRUE){
            $this->session->set_flashdata("message",1);
            redirect("pemberian_beasiswa/pemberian_beasiswa_info/$insert[id]");
        }else if($insert['status'] == FALSE){
            $this->session->set_flashdata("message",8);
            redirect("pemberian_beasiswa");
        }
    }
    
   function pemberian_beasiswa_info($id){
       $this->data['content'] = 'pemberian_beasiswa/pemberian_beasiswa_info';
       $this->data['linkBack'] = "pemberian_beasiswa";
       $this->data['titlePage'] = "Detail Pemberian Beasiswa";
       $this->data['keuanganAdikAsuh'] = $this->m_keuangan_adik_asuh->getKeuanganAdikAsuhById($id);
       $this->render($this->data);
   }
   function unapprove_pemberian_beasiswa($id,$bulan,$tahun,$jumlah){
       $update = $this->m_pemberian_beasiswa->unapprovePemberianBeasiswa($id,$bulan,$tahun,$jumlah);
       if($update){
            $this->session->set_flashdata("message",1);
       }else{
            $this->session->set_flashdata("message",1);
       }
        
       redirect("rekap_keuangan_bulanan/index/$bulan/$tahun");
   }
}
?>
